<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>menu_set.html</title>
    <%@ include file="../inc.jsp" %>
  </head>
  <body class="easyui-layout">
  <!-- 
    <div data-options="region:'north',border:false" style="height: 0px; overflow: hidden;padding:0px">
    </div>
     -->
    <div data-options="region:'center',border:false"
            style="overflow: hidden;padding:0px" fit="true">
	    <table id="dg" title="系统功能菜单列表" fit="true" 
	        url="${baseUrl }/admin/modules/list" method="get" data-options="toolbar:'#toolbar'" pagination="false" rownumbers="true" idField="id" treeField="name" state="closed">    
		    <thead>    
		        <tr>    
		            <th field="name" width="160" align="left">菜单名称</th>    
                    <th field="type" width="80" align="center" formatter="showType">菜单类型</th>    
		            <th field="url" width="240" align="left">链接地址</th>    
		            <th field="show_order" width="80" align="center">显示顺序</th>    
		            <th field="img" width="100">图标</th>    
		            <th field="over_img" width="100">鼠标停留时图标</th>    
		            <th field="status" width="80" align="center" formatter="showStatus">状态</th>    
		        </tr>    
		    </thead>    
		</table>
	</div> 
	<!-- 功能菜单 -->
	<div id="toolbar" style="display: none;" align="left">
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-add',plain:true" onclick="add_fun();" id="add">添加</a>
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-edit',plain:true" onclick="edit_fun();" id="update">修改</a>
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-remove',plain:true" onclick="delete_fun();" id="delete">删除</a>
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-add',plain:true" onclick="update_action();" id="action">Action</a>
            <!-- 
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="$('#searchForm').form('reset');">清空条件</a>
             -->
            <script type="text/javascript">
            function add_fun()
            {
                var params = {
                        winId:'win_add_modules',
                        title:'添加功能菜单',
                        width:400,
                        height:350,
                        showUrl:'${baseUrl}/admin/modules/au_page',
                        okUrl:'${baseUrl}/admin/modules/save',
                        refresh_fun:function(){
                            $('#dg').treegrid('reload');
                        }
                        
                };
            	open_fun(params);
            }
            function edit_fun()
            {
                var moduleId=0;
                var row = $('#dg').datagrid('getSelected');
                if(row)
                {
                    moduleId = row.id;
                }
                if(moduleId>0)
                {
                    //winId,title,width,height,showUrl,okUrl,refresh_fun
                    var params = {
                            winId:'win_edit_modules',
                            title:'修改功能菜单',
                            width:400,
                            height:350,
                            showUrl:'${baseUrl}/admin/modules/au_page?moduleId='+moduleId,
                            okUrl:'${baseUrl}/admin/modules/save',
                            refresh_fun:function(){
                                $('#dg').treegrid('reload');
                            }
                            
                    };
                	open_fun(params);	
                }
                else
                {
                	$.messager.alert("提示","请选择要修改的信息!","info");
                }
            }
            function delete_fun()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("提示","请选择要删除的数据！","info");
                }
                else
                {
                    $.messager.confirm("删除确认","是否要删除你选择的数据？",function(conf){
                        if(conf)
                        {
                            var url = "${baseUrl}/admin/modules/delete?id="+row.id;
                            $.getJSON(url, function(json){
                                if(json.success==0)
                                {
                                    $('#dg').treegrid('reload');
                                }
                                else
                                {
                                    showErrMsg(json);
                                }
                            });
                        }                                       
                    });
                }
                
            }
            function update_action()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("提示","请选择要管理操作地址的功能菜单！","info");
                }
                else
                {
                    $('#mod_id').val(row.id);
                    var url = "${baseUrl}/admin/moduleActions/index?id="+row.id;
                    var params = {
                            winId:'win_action_modules',
                            title:'设置访问URL',
                            width:350,
                            height:300,
                            showUrl:url,
                            refresh_fun:function(){
                                $('#dg').treegrid('reload');
                            }
                            
                    };
                    open_fun(params);   
                }
        
            }
            </script>
	</div>
	
    <script type="text/javascript">
    	var updateFlag=false;
    	
    	 $(document).ready(init);
	     function init() {
	         $('#dg').treegrid({             
	             onLoadSuccess: function(row,data) {
	            	 $('#dg').treegrid('expandAll');
	             	if(data.success != 0)
	             	{
	             		showErrMsg(data);
	             	}
	             }
	         });
	     }    
    	
    	function showStatus(value,rec,index)
    	{
    		if(value==0)
    			return "<font color='red'>禁用</font>";
    		else if(value==9)
    			return "<font color='green'>启用</font>";
    		else
    			return value;
    	}		
    	function showType(value,rec,index)
    	{
            if(value==1)
                return "<font color='blue'>菜单组</font>";
            else if(value==2)
                return "<font color='green'>菜单项</font>";
            else
                return "<font color='red'>功能</font>";
    	}
	</script>
	
  </body>
</html>
